package visual;

import java.awt.Graphics;
import java.awt.Point;
import java.util.Vector;

import javax.swing.JPanel;

import main.GameDef;

public class Piece /*extends JPanel*/ implements GameDef{

	public Vector<Block>blocks;
	
	public Piece(int type, Point pos, boolean vertical){
		blocks = getBlocks(type, pos, vertical);
	}
	
	public void paint(Graphics g){
		for(int i = 0; i < blocks.size(); i++){
			blocks.get(i).paint(g);
		}
	}
	
	public Vector<Block> getBlocks(int type, Point pos, boolean vertical){
		int vectorSize = 0;
		int pieceWidth = 0;
		Vector<Block> temp = new Vector<Block>(0);

		switch(type){
			case ID_INTERIOR:
			case ID_HOUSE:
				vectorSize = 1;
				pieceWidth = 1;
				break;
			case ID_CATAPULT:
				vectorSize = 3;
				pieceWidth = 1;
				break;
			case ID_CANNON:
				vectorSize = 6;
				pieceWidth = 2;
				break;
			case ID_ARMORY:
				vectorSize = 9;
				pieceWidth = 3;
				break;
		}
		
		pos.translate(-(pos.x % BLOCK_WIDTH), -(pos.y % BLOCK_HEIGHT));
		for(int i = 0; i < vectorSize; i++){
			Point blockPos = pos.getLocation();
			if(vertical){
				blockPos.translate((i % pieceWidth) * BLOCK_WIDTH, (i / pieceWidth) * BLOCK_HEIGHT);
			} else {
				blockPos.translate((i / pieceWidth) * BLOCK_WIDTH, (i % pieceWidth) * BLOCK_HEIGHT);	
			}
			temp.add(new Block(type, blockPos));
		}
		return temp;
	}
}
